/**
 * @description  菜单禁用的条件
 * @author Ling
 * @date 2024-08-08
 */

import { IDomEditor, DomEditor } from '@wangeditor/editor';

// 提醒禁用菜单
export function isMentionDisabled(editor: IDomEditor): boolean {
  if (editor.selection == null) return true;

  const selectedElems = DomEditor.getSelectedElems(editor);
  const notMatch = selectedElems.some((elem) => {
    const { type } = elem;
    if (editor.isVoid(elem)) return true;
    if (['pre', 'code', 'link', 'h1', 'h2', 'h3', 'uploadDocx','divider', 'insertArticle'].includes(type)) return true;
  });
  if (notMatch) return true; // disabled
  return false; // enable
}

// 普通链接的禁用
export function isLinkDisabled(editor: IDomEditor): boolean {
  if (editor.selection == null) return true;

  const selectedElems = DomEditor.getSelectedElems(editor);
  const notMatch = selectedElems.some((elem) => {
    const { type } = elem;
    if (editor.isVoid(elem)) return true;
    if (['pre', 'code', 'link', 'insertArticle', "uploadDocx",'divider'].includes(type)) return true;
  });
  if (notMatch) return true; // disabled
  return false; // enable
}

// 插入文章的禁言
export function isUploadDocxDisabled(editor: IDomEditor): boolean {
  if (editor.selection == null) return true;

  const selectedElems = DomEditor.getSelectedElems(editor);
  const notMatch = selectedElems.some((elem) => {
    const { type } = elem;
    if (editor.isVoid(elem)) return true;
    if (['pre', 'code', 'link', 'h1', 'h2', 'h3','divider', 'insertArticle','mention'].includes(type)) return true;
  });
  if (notMatch) return true; // disabled
  return false; // enable
}
